home *** CD-ROM | disk | FTP | other *** search
/ The Guided Tour of Multimedia (Second Edition) / The Guided Tour of Multimedia (Second Edition).iso / trials / qtw111 / samples / winplay1.c < prev    next >
C/C++ Source or Header  |  1993-03-13  |  4KB  |  180 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // WinPlay1.c - Sample QuickTime for Windows Application
  5. //
  6. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  7. //
  8. // ---------------------------------------------------------------------
  9.  
  10. #include <windows.h>
  11. #include <qtw.h>
  12.  
  13. long FAR PASCAL __export WndProc (HWND, UINT, WPARAM, LPARAM);
  14.  
  15. MovieFile mfMovie;
  16. RECT rcMovie;
  17. Movie mMovie;
  18. MovieController mcController;
  19.  
  20.  
  21. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  22.    LPSTR lpszCmdParam, int nCmdShow)
  23.    {
  24.    static char szAppName[] = "WinPlay1";
  25.    HWND        hWnd;
  26.    MSG         msg;
  27.    WNDCLASS    wndclass;
  28.  
  29. // Establish links to QuickTime for Windows
  30.  
  31.    if (QTInitialize (NULL))
  32.       {
  33.       MessageBox (NULL, "QTInitialize failure", szAppName, MB_OK);
  34.       return 0;
  35.       }
  36.  
  37. // Allocate memory required for playing movies
  38.  
  39.    if (EnterMovies ())
  40.       {
  41.       MessageBox (NULL, "EnterMovies failure", szAppName, MB_OK);
  42.       return 0;
  43.       }
  44.  
  45. // Register and create main window
  46.  
  47.    if (!hPrevInstance)
  48.       {
  49.       wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  50.       wndclass.lpfnWndProc   = WndProc;
  51.       wndclass.cbClsExtra    = 0;
  52.       wndclass.cbWndExtra    = 0;
  53.       wndclass.hInstance     = hInstance;
  54.       wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION);
  55.       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  56.       wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  57.       wndclass.lpszMenuName  = NULL;
  58.       wndclass.lpszClassName = szAppName;
  59.  
  60.       if (!RegisterClass (&wndclass))
  61.          {
  62.          MessageBox (NULL, "RegisterClass failure", szAppName, MB_OK);
  63.          return 0;
  64.          }
  65.       }
  66.  
  67.    hWnd = CreateWindow(szAppName, szAppName, WS_CAPTION | WS_SYSMENU |
  68.       WS_CLIPCHILDREN | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT,
  69.       CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  70.  
  71.    if (hWnd == NULL)
  72.       {
  73.       MessageBox (NULL, "CreateWindow failure", szAppName, MB_OK);
  74.       return 0;
  75.       }
  76.  
  77. // Instantiate the movie
  78.  
  79.    if (OpenMovieFile ("SAMPLE.MOV", &mfMovie, OF_READ) != noErr)
  80.       {
  81.       MessageBox (NULL, "OpenMovieFile failure", szAppName, MB_OK);
  82.       return 0;
  83.       }
  84.  
  85.    NewMovieFromFile (&mMovie, mfMovie, NULL, NULL, 0, NULL);
  86.    CloseMovieFile (mfMovie);
  87.  
  88. // Instantiate the movie controller
  89.  
  90.    GetMovieBox (mMovie, &rcMovie);
  91.    OffsetRect(&rcMovie, -rcMovie.left, -rcMovie.top);
  92.    mcController = NewMovieController (mMovie, &rcMovie,
  93.       mcTopLeftMovie + mcScaleMovieToFit, hWnd);
  94.  
  95. // Make the movie paused initially
  96.  
  97.    MCDoAction (mcController, mcActionPlay, 0);
  98.  
  99. // Eliminate the grow box
  100.  
  101.    SetRectEmpty (&rcMovie);
  102.    MCDoAction (mcController, mcActionSetGrowBoxBounds, &rcMovie);
  103.  
  104. // Make the frame just big enough for the movie
  105.  
  106.    MCGetControllerBoundsRect (mcController, &rcMovie);
  107.    AdjustWindowRect (&rcMovie, WS_CAPTION | WS_OVERLAPPED, FALSE);
  108.    OffsetRect(&rcMovie, -rcMovie.left, -rcMovie.top);
  109.    SetWindowPos (hWnd, 0, 0, 0,
  110.       rcMovie.right, rcMovie.bottom, SWP_NOMOVE | SWP_NOZORDER);
  111.  
  112. // Make the movie active
  113.  
  114.    SetMovieActive (mMovie, TRUE);
  115.  
  116. // Make the main window visible
  117.  
  118.    ShowWindow (hWnd, nCmdShow);
  119.    UpdateWindow (hWnd);
  120.  
  121. // Play the movie
  122.  
  123.    while (GetMessage (&msg, NULL, 0, 0))
  124.       {
  125.       TranslateMessage (&msg);
  126.       DispatchMessage (&msg);
  127.       }
  128.  
  129. // Destroy the movie controller
  130.  
  131.    DisposeMovieController (mcController);
  132.  
  133. // Destroy the movie
  134.  
  135.    DisposeMovie (mMovie);
  136.  
  137. // Cut the connections to QuickTime for Windows
  138.  
  139.    ExitMovies ();
  140.    QTTerminate ();
  141.  
  142. // Return to Windows
  143.  
  144.    return msg.wParam;
  145.    }
  146.  
  147.  
  148. long FAR PASCAL __export WndProc (HWND hWnd, UINT message, WPARAM wParam,
  149.    LPARAM lParam)
  150.    {
  151.    PAINTSTRUCT ps;
  152.  
  153. // Drive the movie controller
  154.  
  155.    if (MCIsPlayerMessage (mcController, hWnd, message, wParam, lParam))
  156.       return 0;
  157.  
  158. // Process the windows message
  159.  
  160.    switch (message)
  161.       {
  162.       case WM_PAINT:
  163.  
  164.          if (!BeginPaint (hWnd, &ps))
  165.             return 0;
  166.          EndPaint (hWnd, &ps);
  167.          return 0;
  168.  
  169.       case WM_DESTROY:
  170.  
  171.          PostQuitMessage (0);
  172.          return 0;
  173.       }
  174.  
  175. // Return to Windows
  176.  
  177.    return DefWindowProc (hWnd, message, wParam, lParam);
  178.    }
  179.  
  180.